﻿using System.Data.SqlClient;
using BLL.Services.Pokemons.Listing;

namespace BLL.Services.Pokemons
{
    public class PokemonsService : IPokemonsService
    {
        private readonly PokemonsCollection _pokemonsCollection;

        public PokemonsService(PokemonsCollection pokemonsCollection)
        {
            _pokemonsCollection = pokemonsCollection;
        }

        public Pokemon GetById(int pokemonId)
        {
            try
            {
                return _pokemonsCollection.GetById(pokemonId);
            }
            catch (SqlException ex)
            {
                throw new ServiceException(ex.Message);
            }
        }

        public void Create(Pokemon model)
        {
            try
            {
                _pokemonsCollection.Create(model);
            }
            catch (SqlException ex)
            {
                throw new ServiceException(ex.Message);
            }
        }

        public void Save(Pokemon model)
        {
            try
            {
                _pokemonsCollection.Save(model);
            }
            catch (SqlException ex)
            {
                throw new ServiceException(ex.Message);
            }
        }

        public void Delete(int pokemonId)
        {
            try
            {
                _pokemonsCollection.Delete(pokemonId);
            }
            catch (SqlException ex)
            {
                throw new ServiceException(ex.Message);
            }
        }

        public PokemonListing GetPokemonsListing(int page, int size, string column, int direction, PokemonFilter filter)
        {
            try
            {
                return _pokemonsCollection.GetPokemonListing(page, size, column, direction, filter);
            }
            catch (SqlException ex)
            {
                throw new ServiceException(ex.Message);
            }
        }
    }
}
